#include "Thread.h"

Thread::Thread()
    : isRunning(true), thread(NULL)
{
}

Thread::~Thread()
{
}

void Thread::start()
{
    if (thread == NULL)
    {
        init();
        thread = SDL_CreateThread(threadMain, NULL, this);
    }
}

void Thread::init()
{
}

void Thread::quit(bool waitForThread)
{
    isRunning = false;
    if (waitForThread)
    {
        cleanUp();
        SDL_WaitThread(thread, NULL);
    }
}

void Thread::cleanUp()
{
}

int Thread::threadMain(void* self)
{
    ((Thread*) self)->loop();
    return 0;
}

void Thread::loop()
{
    while (isRunning)
    {
        mainLoop();
    }
}
